package com.zlwy.view;

import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
/**
 * K线图标类基类
 * @author acer
 *
 */
public class BaseChart extends View implements OnTouchListener{

	public BaseChart(Context context){
		super(context);
	}
	
	public BaseChart(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}
	/**
	 * 测量视图及其内容，以确定测量宽度和测量高度。
	 * 这种方法是通过测量（INT，INT）调用，应该由子类进行重写，以提供其内容的准确，高效的测量。
	 * 继承自android.view.View
	 */
	protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		setMeasuredDimension(measureWidth(widthMeasureSpec),measureHeight(heightMeasureSpec));
	}
	/**
	 * 通过查看系统调用时的这一观点改变的焦点状态。
	 * 当焦点更改事件是由定向导航，方向和previouslyFocusedRect洞察其中的重点是来自。
	 * 当重写时，一定要调用通过对超类，以便将出现的标准对焦处理。
	 */
	protected void onFocusChanged(boolean gainFocus, int direction,Rect previouslyFocusedRect) {
		super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
	}
	/**
	 * 测量宽度
	 * @param measureSpec 测量规则
	 * @return
	 */
	private int measureWidth(int measureSpec) {
		int result = 0;
		int specMode = MeasureSpec.getMode(measureSpec);
		int specSize = MeasureSpec.getSize(measureSpec);

		if (specMode == MeasureSpec.EXACTLY) {
			result = specSize;
		} else if (specMode == MeasureSpec.AT_MOST) {
			result = Math.min(result, specSize);
		}
		return result;
	}
	/**
	 * 测量高度
	 * @param measureSpec 测量规则
	 * @return
	 */
	private int measureHeight(int measureSpec) {
		int result = 0;
		int specMode = MeasureSpec.getMode(measureSpec);
		int specSize = MeasureSpec.getSize(measureSpec);

		if (specMode == MeasureSpec.EXACTLY) {
			result = specSize;
		} else if (specMode == MeasureSpec.AT_MOST) {
			result = Math.min(result, specSize);
		}
		return result;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		// TODO Auto-generated method stub	
		return false;
	}
}
